﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZhouYu.DreamTour.BLL.IService;
using ZhouYu.DreamTour.DAL.IRepository;
using ZhouYu.DreamTour.Model;
using ZhouYu.DreamTour.ViewModel;

namespace ZhouYu.DreamTour.BLL.Service
{
   public class OrderService:IOrderService
    {

        private IOrderRepository _orderrepository;
        private IScenicRepository _scenicRepository;
        public OrderService(IOrderRepository orderrepository,IScenicRepository scenicRepository)
        {
            _orderrepository = orderrepository;
            _scenicRepository = scenicRepository;
        }
        /// <summary>
        /// 获取用户订单类型集合
        /// </summary>
        /// <param name="Order_Name">订单类型</param>
        /// <returns></returns>
        public List<OrderInfo> GetOrder(int id)
        {
            return _orderrepository.GetOrder(id);
        }

        /// <summary>
        /// 修改商品为到货状态
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public int UpdateArrival(int id)
        {
            return _orderrepository.UpdateArrival(id);
        }
        /// <summary>
        /// 取消订单
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public int CancelSpecialty(int id)
        {
            return _orderrepository.CancelSpecialty(id);
        }

        //添加商品评价
        public int AddCommodityevaluate(Usercomment usercomment)
        {
            return _orderrepository.AddCommodityevaluate(usercomment);
        }

        /// <summary>
        /// 修改商品为已评价
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public int Alreadyevaluated(int id)
        {
            return _orderrepository.Alreadyevaluated(id);
        }
        //查询订单状态
        public List<OrderInfo> Orderstatus(int status, int UserId)
        {
            return _orderrepository.Orderstatus(status, UserId);
        }

        #region 添加订单信息
        /// <summary>
        /// 添加订单信息
        /// </summary>
        /// <param name="orderInfo"></param>
        /// <returns></returns>
        public ResponseResult AddOrderInfo(OrderInfo orderInfo,int Id)
        {
            ResponseResult responseResult = new ResponseResult();
            //根据ID查询景点详情
            var TouristRouteInfo = _scenicRepository.GetScenicDetails(Id);
            //将对象属性赋值
            orderInfo.Order_ProInfo = TouristRouteInfo.TName;
            orderInfo.Order_Type = "旅游团购";
            orderInfo.Order_Money = TouristRouteInfo.Price;
            orderInfo.Order_OutingTime = DateTime.Parse(TouristRouteInfo.OutDate);
            orderInfo.Order_ReserveTime = DateTime.Parse(TouristRouteInfo.OutDate);
            orderInfo.Order_Status = 0;
            orderInfo.Order_Name = "心悦";
            orderInfo.Orde_PictureUrl = TouristRouteInfo.Pic_Url;
            orderInfo.Order_Content = TouristRouteInfo.RouteIntroduce;
            responseResult.Success = _orderrepository.AddOrderInfo(orderInfo);
            return responseResult;
        }
        #endregion

        #region 添加团购订单信息
        /// <summary>
        /// 添加订单信息
        /// </summary>
        /// <param name="orderInfo"></param>
        /// <returns></returns>
        public ResponseResult AddGroupOrderInfo(OrderInfo orderInfo)
        {
            ResponseResult responseResult = new ResponseResult();;
            //将对象属性赋值
            orderInfo.Order_ReserveTime = DateTime.Now;
            responseResult.Success = _orderrepository.AddOrderInfo(orderInfo);
            return responseResult;
        }
        #endregion

        #region 根据订单号查询订单信息
        /// <summary>
        /// 根据订单号查询订单信息
        /// </summary>
        /// <param name="Order_No"></param>
        /// <returns></returns>
        public ResponseResult SelOrderInfoByNo(string Order_No)
        {
            ResponseResult responseResult = new ResponseResult();
            responseResult.data=_orderrepository.SelOrderInfoByNo(Order_No);
            return  responseResult;
        }
        #endregion

        #region 修改订单状态
        /// <summary>
        /// 修改订单状态
        /// </summary>
        /// <param name="Order_No"></param>
        /// <param name="Status"></param>
        /// <returns></returns>
        public ResponseResult UpdateOrderStatus(string Order_No, int Status)
        {
            ResponseResult responseResult = new ResponseResult();
            responseResult.Success=_orderrepository.UpdateOrderStatus(Order_No, Status);
            return responseResult;
        }
        #endregion
    }
}
